package com.jinyou.utils.spring;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.danga.MemCached.MemCachedClient;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


public class ParameterException implements HandlerExceptionResolver {
    private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ParameterException.class);

    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView mv = new ModelAndView();

        FastJsonJsonView view = new FastJsonJsonView();
        Map attributes = new HashMap();
        attributes.put("status", Integer.valueOf(0));
        attributes.put("type", "paramErrorType");
        attributes.put("error", ex.getMessage());
        view.setAttributesMap(attributes);
        mv.setView(view);
        MemCachedClient.log.debug("异常:" + ex.getMessage(), ex);
        return mv;
    }
}
